package com.xneure.function.enums;

import com.xneure.utils.ObjectUtil;

public enum TokenType{
	UNKNOWN("未知",""),
	VALUE("数据","1"),
	KEYWORD("关键字","@kw"),
	FUNCTION("函数","fun"),
	ADD("加法","+"),
	SUBTRACTION("减法","-"),
	MULTIPLICATION("乘法","*"),
	DIVISION("除法","/"),
	DOT("逗号",	","),
	LEFT_BRACKETS("左括号","("),
	RIGHT_BRACKETS("右括号",")"),
	OR("或者","or"),
	AND("并且","and"),;
	private String title;
	private String mak;
	private static int length = values().length;
	TokenType(String t,String m){
		title = t;
		this.mak = m;
	}

	public String getTitle(){
		return title;
	}

	public String getMak(){
		return mak;
	}

	public static TokenType formTokenType(String str){
		if(ObjectUtil.isNull(str)) {
			return UNKNOWN;
		}
		TokenType[] values = values();
		str = str.toLowerCase();
		if(str.length()==1) {
			for (int i = ADD.ordinal(); i < OR.ordinal(); i++) {
				if(str.equals(values[i].mak)){
					return values[i];
				}
			}
		}else {
			for (int i = OR.ordinal(); i < length; i++) {
				if(str.equals(values[i].mak)){
					return values[i];
				}
			}
		}
		return UNKNOWN;
	}

	public static boolean include(String str){
		if(ObjectUtil.isNull(str)) {
			return false;
		}
		TokenType[] values = values();
		str = str.toLowerCase();
		if(str.length()==1) {
			for (int i = ADD.ordinal(); i < OR.ordinal(); i++) {
				if(str.equals(values[i].mak)){
					return true;
				}
			}
		}else {
			for (int i = OR.ordinal(); i < length; i++) {
				if(str.equals(values[i].mak)){
					return true;
				}
			}
		}
		return false;
	}
}
